int backgroundcolor(int bgcolor) {

  /*
   Background
   colors
   0 black
   1 red
   2 green
   3 yellow (red/green)
   4 blue
   5 purple (red/blue)
   6 light blue (green/blue)
   7 white
   
   */

  int x;

  for(x = 0; x < divisions; x++)
  {
    write_page(x, RGB(bitRead(bgcolor,0), bitRead(bgcolor,1),bitRead(bgcolor,2)));  
  }

}


/*

 clockhand colors
 0 black
 1 red
 2 green
 3 yellow (red/green)
 4 blue
 5 purple (red/blue)
 6 light blue (green/blue)
 7 white
 
 */


int hourclockhand(int outsidecolor, int insidecolor) {

  if (hour == 0) {

    write_page(3, RGB(bitRead(outsidecolor,0), bitRead(outsidecolor,1),bitRead(outsidecolor,2)));  

    write_page(2, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2))); 
    write_page(1, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2))); 
    write_page(0, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2))); 
    write_page(254, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2)));  
    write_page(253, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2)));  

    write_page(252, RGB(bitRead(outsidecolor,0), bitRead(outsidecolor,1),bitRead(outsidecolor,2)));   


  }  

  else

  {
    write_page(DisplayHour-1, RGB(bitRead(outsidecolor,0), bitRead(outsidecolor,1),bitRead(outsidecolor,2)));  

    write_page(DisplayHour, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2))); 
    write_page(DisplayHour+1, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2))); 
    write_page(DisplayHour+2, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2))); 
    write_page(DisplayHour+3, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2)));  

    write_page(DisplayHour+4, RGB(bitRead(outsidecolor,0), bitRead(outsidecolor,1),bitRead(outsidecolor,2)));

  }

}

int minuteclockhand(int outsidecolor, int insidecolor) {  
  //minute hand
  write_page(DisplayMinute-1, RGB(bitRead(outsidecolor,0), bitRead(outsidecolor,1),bitRead(outsidecolor,2)));  

  write_page(DisplayMinute, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2)));
  write_page(DisplayMinute+1, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2)));

  write_page(DisplayMinute+2, RGB(bitRead(outsidecolor,0), bitRead(outsidecolor,1),bitRead(outsidecolor,2)));  

}


//Second hand


int secondclockhand(int outsidecolor, int insidecolor) {  
  


  if (RTC.get(DS1307_SEC,false) > 0) {
    
    //254 / seconds = 4.25
  write_page(DisplaySecond-1, RGB(bitRead(outsidecolor,0), bitRead(outsidecolor,1),bitRead(outsidecolor,2)));  

   write_page(DisplaySecond, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2)));

   write_page(DisplaySecond+1, RGB(bitRead(outsidecolor,0), bitRead(outsidecolor,1),bitRead(outsidecolor,2)));  



 }

  else

 {

    
    write_page(254, RGB(bitRead(outsidecolor,0), bitRead(outsidecolor,1),bitRead(outsidecolor,2)));  

    write_page(0, RGB(bitRead(insidecolor,0), bitRead(insidecolor,1),bitRead(insidecolor,2)));

    write_page(1, RGB(bitRead(outsidecolor,0), bitRead(outsidecolor,1),bitRead(outsidecolor,2)));  
    
  
  }   

}


//Dial
int dial(int dialcolor) {
double y;

  for(y =  0; y < divisions; y=y + 21.33333333333333 ) {

    write_page(y, RGB(bitRead(dialcolor,0), bitRead(dialcolor,1),bitRead(dialcolor,2)));  

  }

}




void clock1(void){

  
 copy_page(); 
  //flip_page();




  //Background
  int x;

  for(x = 0; x < divisions; x++)
  {

    if (x <= 64) {
      write_page(x, RGB(1,0,1)); 
    }

    if (x > 64 && x < 128) {
      write_page(x, RGB(1,1,0)); 
    }

    if (x >= 128 && x < 192) {
      write_page(x, RGB(0,1,1)); 
    }

    if (x >= 192) {
      write_page(x, RGB(1,1,1));
    }
  }



  dial(0);
  
  hourclockhand (0,1); 
  minuteclockhand (0,2);
  secondclockhand(0,4);

  //second hand





  flip_page();    



 // clear_page();

}

void clock2(void){


 copy_page(); 
  //flip_page();




  //Background
  backgroundcolor(0);



  dial(7);


  hourclockhand(1,1);
  //minute hand
  minuteclockhand(6,6);
  //second hand
  secondclockhand(4,4);

  flip_page();    



 // clear_page();

}

void clock3(void){


  copy_page(); 
  //flip_page();




  //Background
  backgroundcolor(3);

  dial(2);


  hourclockhand (0,2);
  minuteclockhand (0,2);
  secondclockhand (0,2);


  flip_page();    



  // clear_page();

}

void clock4(void){


  copy_page(); 
  //flip_page();




  //Background
  backgroundcolor(0);


  hourclockhand(1,1);
  //minute hand
  minuteclockhand(6,6);
  //second hand
  secondclockhand(2,2);

  flip_page();    



  // clear_page();

}

void clock5(void){


  copy_page(); 
  //flip_page();




  backgroundcolor(4);
  dial(0);
  hourclockhand (0,1);
  minuteclockhand (0,6);  


  //second hand
  secondclockhand (0,2); 
  

  flip_page();    





}

void clock6(void){

  copy_page;  

  backgroundcolor(7);

  hourclockhand (0,0);
  minuteclockhand (0,0);
  secondclockhand (0,0);


  flip_page();  

}

void clock7(void){

  copy_page;  

  backgroundcolor(0);

  hourclockhand (7,7);
  minuteclockhand (7,7);
  secondclockhand (7,7);


  flip_page();  

}

void clock8(void){

  copy_page;  

  backgroundcolor(0);

  hourclockhand (2,2);
  minuteclockhand (2,2);
  secondclockhand (2,2);
  
  dial (2);


  flip_page();  

}

void clock9(void){

  copy_page;  

  backgroundcolor(0);
dial (4);
  hourclockhand (4,4);
  minuteclockhand (4,4);
  secondclockhand (4,4);
  
  


  flip_page();  

}

void clock10(void){

  copy_page;  

  backgroundcolor(7);
  dial (0);
  hourclockhand (0,1);
  minuteclockhand (0,6);
  secondclockhand (0,2);
  
  


  flip_page();  

}

void clock11(void){

    copy_page; 
    int x;
  for(x = 0; x < divisions; x++)
  {
      switch (x % 8)
      {
        case 0:
          write_page(x, RGB(0,0,0));
          break;  
        case 1:
          write_page(x, RGB(1,0,0));
          break;
        case 2:
          write_page(x, RGB(0,1,0));
          break;
        case 3:
          write_page(x, RGB(0,0,1));
          break;
        case 4:
          write_page(x, RGB(1,1,0));
          break;  
        case 5:
          write_page(x, RGB(1,0,1));
          break;  
        case 6:
          write_page(x, RGB(0,1,1));
          break;  
        case 7:
          write_page(x, RGB(1,1,1));
          break;
      }
    }
    flip_page(); 

}




